App({
  globalData: {
    userInfo: null,
    hasLogin: false,
    // 用户健康数据
    healthData: {
      height: 0,
      weight: 0,
      age: 0,
      gender: '',
      goal: '', // 健康目标：减重/增肌/保持
      dietaryRestrictions: [], // 饮食限制
    },
    // 营养摄入目标
    nutritionGoals: {
      calories: 0,
      protein: 0,
      carbs: 0,
      fat: 0,
      fiber: 0
    }
  },
  
  onLaunch: function() {
    // 检查登录状态
    const token = wx.getStorageSync('token')
    if (token) {
      // 验证token有效性
      wx.request({
        url: 'http://localhost:3000/api/users/profile',
        method: 'GET',
        header: {
          'Authorization': `Bearer ${token}`
        },
        success: (res) => {
          if (res.statusCode === 200) {
            this.globalData.hasLogin = true
            this.globalData.userInfo = res.data
          } else {
            // token无效，清除存储
            wx.removeStorageSync('token')
            this.globalData.hasLogin = false
            this.globalData.userInfo = null
          }
        },
        fail: () => {
          // 请求失败，清除存储
          wx.removeStorageSync('token')
          this.globalData.hasLogin = false
          this.globalData.userInfo = null
        }
      })
    }
  },

  // 获取用户信息
  getUserInfo: function() {
    // 这里可以调用后端API获取用户详细信息
    // TODO: 实现获取用户信息的API调用
  }
}) 